/*
 * GWLGoalsDistributor.java
 * Created on 14 déc. 2008
 *
 * Glacéo Internet Platform
 * http://sourceforge.net/projects/chm/
 *
 * Copyright (c) 2005-2009, Jens and Jan Janke (VirtualHockey Project)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hockeo.vhbase.data.impl.goals;


import java.math.BigDecimal;
import java.math.RoundingMode;

import com.hockeo.vhbase.conf.GRulesConstants;
import com.hockeo.vhbase.data.dao.club.GClub;
import com.hockeo.vhbase.data.dao.contest.GContestElement;

/**
 * Goals distributor for the World League.
 *
 * @version $Id$
 * @author jjanke
 */
public class GWLGoalsDistributor implements IGGoalsDistributor
{
  private BigDecimal d_decGoals;

  public void initialize( GContestElement element )
  {
    switch ( element.getContestRound().getRoundType() )
    {
      case QUALIFICATION_1:
      {
        d_decGoals = BigDecimal.valueOf( ( 2.5 + 6 + 4 + 7.5 ) * GRulesConstants.GOALS_PER_MATCH_AVG );
        break;
      }
      case ROUND_MAIN:
      {
        d_decGoals = BigDecimal.valueOf( ( 6 + 4 + 7.5 ) * GRulesConstants.GOALS_PER_MATCH_AVG );
        break;
      }
      case ROUND_INTERMEDIATE:
      {
        d_decGoals = BigDecimal.valueOf( ( 4 + 7.5 ) * GRulesConstants.GOALS_PER_MATCH_AVG );
        break;
      }
      case QUARTER_FINAL:
      {
        d_decGoals = BigDecimal.valueOf( 7.5 * GRulesConstants.GOALS_PER_MATCH_AVG );
        break;
      }
      case SEMI_FINAL:
      {
        d_decGoals = BigDecimal.valueOf( 5.0 * GRulesConstants.GOALS_PER_MATCH_AVG );
        break;
      }
      case FINAL:
      {
        d_decGoals = BigDecimal.valueOf( 2.5 * GRulesConstants.GOALS_PER_MATCH_AVG );
        break;
      }
      default:
        throw new IllegalStateException( "Unexpected WL round type " + element.getContestRound().getRoundType().name() );
    }

    d_decGoals = d_decGoals.setScale( 1, RoundingMode.UP );
  }

  /**
   * Returns the same amount of goals for every club.
   *
   * @see com.hockeo.vhbase.data.impl.goals.IGGoalsDistributor#getGoals(int)
   */
  public BigDecimal getGoals( int nSeeding )
  {
    return d_decGoals;
  }

  /**
   * Returns the amount of goals to be used in CL KO rounds. The club argument is ignored
   * as all teams benefit from the same amount of goals.
   */
  public BigDecimal getGoals( GClub club )
  {
    return d_decGoals;
  }
}
